<?php

	// +----------------------------------------------------------------------
	// | card版本接口index
	// +----------------------------------------------------------------------
	// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
	// +----------------------------------------------------------------------
	// | Author: 微尘 <yicmf@qq.com>
	// +----------------------------------------------------------------------

	namespace app\controller\api\v3;

    use app\controller\api\pos\Common;

    class Trade extends Common
	{

		/**
		 * 交易管理首页
		 */
		public function index()
		{


            $channel = $this->request->param('channel','all');
            $data['data']['today']['count'] = $this->user->trades()->when($channel !== 'all', function ($query)use($channel) {
                // 满足条件后执行
                $query->where('channel',$channel);
            })->whereTime('create_time', 'today')->where('type',90)->count();
//            $data['data']['today']['num'] = $this->user->moneys()->when($channel !== 'all', function ($query) {
//                // 满足条件后执行
//                $query->where('score', '>', 80)->limit(10);
//            }, function ($query) {
//                // 不满足条件执行
//                $query->where('score', '>', 60);
//            })->whereTime('create_time', 'today')->where('type',90)->sum('money');
            $data['data']['today']['amount'] = $this->user->trades()->when($channel !== 'all', function ($query)use($channel) {
                // 满足条件后执行
                $query->where('channel',$channel);
            })->whereTime('create_time', 'today')->where('type',90)->sum('money');
            $data['data']['month']['num'] = $this->user->trades()->when($channel !== 'all', function ($query)use($channel) {
                // 满足条件后执行
                $query->where('channel',$channel);
            })->whereTime('create_time', 'month')->where('type',90)->count();
            $data['data']['month']['amount'] = $this->user->trades()->when($channel !== 'all', function ($query)use($channel) {
                // 满足条件后执行
                $query->where('channel',$channel);
            })->whereTime('create_time', 'month')->where('type',90)->sum('money');
            // 交易记录
            $data['data']['lists'] = $this->user->trades()->when($channel !== 'all', function ($query)use($channel) {
                // 满足条件后执行
                $query->where('channel',$channel);
            })->order('create_time DESC')->where('type',90)->paginate();

            $data['data']['channel'] = ['ls'=>'立刷','lkl'=>'拉卡拉'];
            $data['code'] = 0;
            return $this->json($data);
		}
		/**
		 * 收益管理首页
		 */
		public function profit()
		{
            $channel = $this->request->param('channel','all');
            $data['data']['today']['flow'] = $this->user->moneys()->when($channel !== 'all', function ($query)use($channel) {
                // 满足条件后执行
                $query->where('channel',$channel);
            })->whereTime('create_time', 'today')->where('type','flow')->sum('money');
            $data['data']['today']['fee'] =  $this->user->moneys()->when($channel !== 'all', function ($query)use($channel) {
                // 满足条件后执行
                $query->where('channel',$channel);
            })->whereTime('create_time', 'today')->where('type','fee')->sum('money');
            $data['data']['today']['back'] =  $this->user->moneys()->when($channel !== 'all', function ($query)use($channel) {
                // 满足条件后执行
                $query->where('channel',$channel);
            })->whereTime('create_time', 'today')->where('type','back')->sum('money');

            $data['data']['month']['flow'] = $this->user->moneys()->when($channel !== 'all', function ($query)use($channel) {
                // 满足条件后执行
                $query->where('channel',$channel);
            })->whereTime('create_time', 'month')->where('type','flow')->sum('money');
            $data['data']['month']['fee'] =  $this->user->moneys()->when($channel !== 'all', function ($query)use($channel) {
                // 满足条件后执行
                $query->where('channel',$channel);
            })->whereTime('create_time', 'month')->where('type','fee')->sum('money');
            $data['data']['month']['back'] =  $this->user->moneys()->when($channel !== 'all', function ($query)use($channel) {
                // 满足条件后执行
                $query->where('channel',$channel);
            })->whereTime('create_time', 'month')->where('type','back')->sum('money');

            // 交易记录
            $data['data']['lists'] =  $this->user->moneys()->when($channel !== 'all', function ($query)use($channel) {
                // 满足条件后执行
                $query->where('channel',$channel);
            })->order('create_time DESC')->where('status',1)->paginate();

            $data['data']['channel'] = ['ls'=>'立刷','lkl'=>'拉卡拉'];
            $data['code'] = 0;
            return $this->json($data);
		}
	}
